#/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 11:47
# @Author  : wyy
# @Email   : 1915059545@qq.com
# @File    : pahe_ttjht.py
# @Software: PyCharm
"""添加合同页面"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep


class PageTianjiaHetong:
    # 定位器
    # 签约时间
    qianyueshijian_locator = (By.CSS_SELECTOR, "#due_time")
    # 来源商机,负责人
    shangjilaiyuan_locator = (By.NAME, "business_name")
    fuzeren_locator = (By.ID, "owner_name")
    # 合同金额
    hetongjine_locator = (By.CSS_SELECTOR, "#price")
    # 合同生效时间
    hetongshengxiaoshijian_locator = (By.NAME, "start_date")
    # 合同到期时间
    hetongdaoqishijian_locator = (By.CSS_SELECTOR, "#end_date")
    # 条件和条款
    tiaojianhetiaokuan_locator = (By.CSS_SELECTOR,
                                  "body > div.container > div.row > div > form > table > tbody > tr:nth-child(7) > td:nth-child(2) > div > div.ke-edit > iframe")
    # 合同描述
    hetongmiaoshu_locator = (By.CSS_SELECTOR, "#description")
    # 保存按钮
    baocun_locator = (By.NAME,"submit")

    #添加保存
    baocun2_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")
    # 勾选商机来源
    gouxuan_locator = (By.XPATH, '//*[@id="data"]/tr[1]/td[1]/input[1]')
    # 确认勾选商机的【确认】
    ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')
    # 勾选负责人
    gouxuanfuzeren_locator = (By.XPATH, '//*[@id="d_content"]/tr[1]/td[1]/input')
    # 确认勾选负责人的【确认】
    ok1_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]')
    def __init__(self,driver):
        self.driver=driver
    #输入签约时间
    def input_qysj(self,qianyueshijian):
        self.driver.find_element(*self.qianyueshijian_locator).send_keys(qianyueshijian)
    #选择来源商机，选择商机
    def input_lysj(self):
        self.driver.find_element(*self.shangjilaiyuan_locator).click()
        self.driver.find_element(*self.gouxuan_locator).click()
        self.driver.find_element(*self.ok_locator).click()
    #选择负责人
    def input_fzr(self):
        self.driver.find_element(*self.fuzeren_locator).click()
        self.driver.find_element(*self.gouxuanfuzeren_locator).click()
        self.driver.find_element(*self.ok1_locator).click()
    #输入合同金额
    def input_htje(self,hetongjine):
        self.driver.find_element(*self.hetongjine_locator).send_keys(hetongjine)
    #输入合同生效时间
    def input_sxsj(self,sxsj):
        self.driver.find_element(*self.hetongshengxiaoshijian_locator).send_keys(sxsj)
    #输入合同到期时间
    def input_dqsj(self,dqsj):
        self.driver.find_element(*self.hetongdaoqishijian_locator).send_keys(dqsj)
    #输入条件和条款
    def input_tjhtk(self,tianjia):
        self.driver.find_element(*self.tiaojianhetiaokuan_locator).send_keys(tianjia)
    #输入合同描述
    def input_htms(self,htms):
        self.driver.find_element(*self.hetongmiaoshu_locator).send_keys(htms)
    #点击保存
    def input_baocun(self):
        self.driver.find_element(*self.baocun2_locator).click()
    #添加合同，依次合法添加
    def add_ht(self,qysj,htje,sxsj,dqsj,tj,htms):
        self.input_lysj()
        sleep(1)
        self.input_qysj(qysj)
        sleep(1)
        self.input_fzr()
        sleep(1)
        self.input_htje(htje)
        sleep(1)
        self.input_sxsj(sxsj)
        sleep(1)
        self.input_dqsj(dqsj)
        sleep(1)
        self.input_tjhtk(tj)
        self.input_htms(htms)
        sleep(1)
        self.input_baocun()
        sleep(1)

    #添加合同，必填项
    def add_ht_btx(self, ):
        self.input_lysj()
        self.input_fzr()
        self.input_baocun()
        sleep(2)





